﻿var wmsBiz = new Object();
//检查物料编码是否存在
wmsBiz.checkMaterialCode = function (materialCode) {
    var table = wmsCommon.execCommand(String.format("wmsql(select * from materials where materialNo='{0}')", materialCode));
    if (table.length == 0)
        return false;
    return true;
}

//保存车辆队列信息
//hkl
wmsBiz.saveQueueAndRefreshPage = function (dataModel) {
    var rtn = wmsCommon.pubSaveMethod(dataModel);   //调用通用保存方法
    if (wmsCommon.checkForNull(rtn) == "") {
        wmsCommon.alert("信息保存失败，请与管理员联系！");
    }
    else {
        if (dataModel == "wp_queue") {
            var rtn1 = wmsBiz.updatePortStatus(rtn);
            if (wmsCommon.checkForNull(rtn) != "") {
                if (confirm("保存成功！  是否关闭窗口？")) {
                    wmsCommon.refParentPage();
                    window.close();
                }
                else {
                    wmsCommon.refPage(rtn);
                }
            } else {
                wmsCommon.alert("信息保存失败，请与管理员联系！");
            }
        }
    }
}
//更新仓口状态
//hkl
wmsBiz.updatePortStatus = function (rtn) {
    var taskNo = rtn.split('&')[0].split('=')[1];
    var queueNo = rtn.split('&')[1].split('=')[1];
    var queueStatus = "01";
    wmsCommon.execCommand(String.format("sys(#QueueManager.UpdateStatus({0},{1},{2}))", taskNo, queueNo, queueStatus));
}
//删除仓口
//验证仓口状态 忙碌则不能删除

wmsBiz.deletePort = function (tableID, modelName, cnModelName) {
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (wmsCommon.checkForNull(allSelectedRow) != "") {
        if (confirm("是否确定要删除选择的信息？")) {
            var keyColumns = allSelectedRow.replace(/,/g, "|");
            var result = wmsCommon.execCommand(String.format("sys(#WarehouseManager.IsPortBusy({0}))", keyColumns));
            if (result == '1') {
                wmsCommon.refThisPage();
                wmsCommon.alert("处于忙碌状态的仓口不允许删除！");             
            }
            else if (result == '2') {      
                wmsCommon.refThisPage();           
            }
            else {
                wmsCommon.alert("操作失败，请与管理员联系！");
            }
        }
    }
    else {
        wmsCommon.alert("请先选择需要删除的信息！");
    }
}


//保存
wmsBiz.saveAndTip = function (dataModel) {
    var rtn = wmsCommon.pubSaveMethod(dataModel);   //调用通用保存方法
    if (wmsCommon.checkForNull(rtn) == "") {
        wmsCommon.alert("信息保存失败，请与管理员联系！");
    }
    else {
        wmsCommon.alert("信息保存成功！");
    }
}

//入库分派 保存
wmsBiz.saveStockInAndTip = function (dataModel, orderno, cmd) {
    var orderNo = orderno;
    var rtn = wmsCommon.pubSaveMethod(dataModel, cmd);   //调用通用保存方法
   
}


//出库分派 保存
wmsBiz.saveStockOutAndTip = function (dataModel, orderno) {
    var orderNo = orderno;
    var rtn = wmsCommon.pubSaveMethod(dataModel);   //调用通用保存方法
    var result = wmsCommon.execCommand(String.format("sys(#StockOutOrderManager.UpdateStockOutOrderState({0}))", orderno));

    if (wmsCommon.checkForNull(rtn) == "") {
        wmsCommon.alert("信息保存失败，请与管理员联系！");
    }
    else {
        if (confirm("保存成功！  是否关闭窗口？")) {
            wmsCommon.refParentPage();
            window.close();
        }
        wmsCommon.refPage(rtn);
        
    }
}

//分派
wmsBiz.allocate = function (obj) {
    
    var keyValue = obj.parentNode.parentNode.keyvalue;

    if (wmsCommon.checkForNull(keyValue) != "") {

        var result = wmsCommon.execCommand(String.format("sys(#StockInOrderManager.IsExistStockInWbs({0}))", keyValue));
        var rootPath = wmsCommon.getRootPath();
        var primary = keyValue;
        if (result == "True") {
            wmsCommon.openWin(rootPath + "/model.aspx?opt=1&model=" + "stockInTask" + "&temp=" + "stockInTask_allocate&beforeLoad=" + escape("sys(#StockInOrderManager.CreateNewTaskByStockInOrder({data}," + primary + "))") + "&beforeSave=" + escape("sys(#StockInTaskManager.StockInTaskBeforeSave({data}))") + "&" + primary + "&actType=1", 900, 600);
        }
        else {

            if (confirm("空库位不够！  是否要存放能分配的物料？")) {
                wmsCommon.openWin(rootPath + "/model.aspx?opt=1&model=" + "stockInTask" + "&temp=" + "stockInTask_allocate&beforeLoad=" + escape("sys(#StockInOrderManager.CreateNewTaskByStockInOrderPart({data}," + primary + "))") + "&" + primary + "&actType=2", 900, 600);

            }
        }

    }

}

//分派stockOut
wmsBiz.allocateStockOut = function (obj) {
    var keyValue = obj.parentNode.parentNode.keyvalue;

    if (wmsCommon.checkForNull(keyValue) != "") {

        var result = wmsCommon.execCommand(String.format("sys(#StockOutOrderManager.IsExistStockOutWbs({0}))", keyValue));
        if (result == "True") {
            var rootPath = wmsCommon.getRootPath();
            var primary = keyValue;
            wmsCommon.openWin(rootPath + "/model.aspx?opt=1&model=" + "stockOutTask" + "&temp=" + "stockOutTask_allocate&beforeLoad=" + escape("sys(#StockOutOrderManager.CreateNewTaskByStockOutOrder({data}," + primary + "))") + "&primary=" + primary, 900, 600);
        }
        else {
            wmsCommon.alert("库存物料不够，请确认有足够的物料！");

        }
    }
}


//入库下发
wmsBiz.stockInSending = function (obj) {
    var keyValue = obj.parentNode.parentNode.keyvalue;

    if (wmsCommon.checkForNull(keyValue) != "") {
        var rootPath = wmsCommon.getRootPath();
        var primary = keyValue;
        wmsCommon.openWin(rootPath + "/model.aspx?opt=1&model=" + "taskSending" + "&temp=" + "stockInTask_sending&beforeLoad=" + escape("sys(#StockInTaskManager.CreateExecuter({data}," + primary + "))") + "&primary=" + primary, 900, 600);
    }
}

//出库下发
wmsBiz.stockOutSending = function (obj, sendingType) {
    var keyValue = obj.parentNode.parentNode.keyvalue;

    if (wmsCommon.checkForNull(keyValue) != "") {
        var rootPath = wmsCommon.getRootPath();
        var primary = keyValue;
//        "&beforeLoad=" + escape("sys(#StockOutTaskManager.CreateExecuter({data}," + primary + "))") +
        wmsCommon.openWin(rootPath + "/model.aspx?opt=1&model=" + "taskSending" + "&temp=" + "stockOutTask_sending&beforeLoad=" + escape("sys(#StockOutTaskManager.CreateExecuter({data}," + primary + "))") + "&primary=" + primary, 900, 800);
    }
}

wmsBiz.stockOutSaveSending = function (obj) {

    var taskNo = document.all("taskSending$taskNo$0").value;
    var userName = document.all("taskSending$excuterNo$0").value;

    if (taskNo == "" || userName == "") {
        wmsCommon.alert("单据和执行人为必填！");
    }

    var result = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateExecuter({0},{1}))", taskNo, userName));
    var resultState = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateStateToSengding({0}))", taskNo));
    if (result == "True" && resultState == "True") {
        wmsCommon.refParentPage();
        wmsCommon.alert("下发成功！");
    }
}

wmsBiz.stockInSaveSending = function (obj) {


    var taskNo = document.all("taskSending$taskNo$0").value;
    var userName = document.all("taskSending$excuterNo$0").value;

    if (taskNo == "" || userName == "") {
        wmsCommon.alert("单据和执行人为必填！");
    }

    var result = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateExecuter({0},{1}))", taskNo, userName));
    var resultState = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateStateToSengding({0}))", taskNo));
    if (result == "True" && resultState == "True") {
        wmsCommon.refParentPage();
        wmsCommon.alert("下发成功！");
    }
}

wmsBiz.selectChange = function (obj) {

    var value = obj.value;
    var index = obj.selectedIndex;
    var text = obj.options[obj.selectedIndex].text;
    if (index == 3 || index == 4 || index == 6) {
        var uiText = document.getElementById("supplierName");
        uiText.style.display = "none";
        var uiLable = document.getElementById("supplier");
        uiLable.style.display = "none";
    }
    else {
        var uiText = document.getElementById("supplierName");
        uiText.style.display = "block";
        var uiLable = document.getElementById("supplier");
        uiLable.style.display = "block";
    }

    if (index == 1 || index == 2 || index == 5) {
        var uiText = document.getElementById("fromWhName");
        uiText.style.display = "none";
        var uiLable = document.getElementById("fromWh");
        uiLable.style.display = "none";
    }
    else {
        var uiText = document.getElementById("fromWhName");
        uiText.style.display = "block";
        var uiLable = document.getElementById("fromWh");
        uiLable.style.display = "block";
    }
}


wmsBiz.selectStockOutChange = function (obj) {

    var value = obj.value;
    var index = obj.selectedIndex;
    var text = obj.options[obj.selectedIndex].text;
    if (index == 3 || index == 4 || index == 7 || index == 8) {
        var uiText = document.getElementById("clientNoName");
        uiText.style.display = "none";
        var uiLable = document.getElementById("clientNo");
        uiLable.style.display = "none";
    }
    else {
        var uiText = document.getElementById("clientNoName");
        uiText.style.display = "block";
        var uiLable = document.getElementById("clientNo");
        uiLable.style.display = "block";
    }

    if (index == 1 || index == 2 || index == 5 || index == 6 || index == 8) {
        var uiText = document.getElementById("toWhNoName");
        uiText.style.display = "none";
        var uiLable = document.getElementById("toWhNo");
        uiLable.style.display = "none";
    }
    else {
        var uiText = document.getElementById("toWhNoName");
        uiText.style.display = "block";
        var uiLable = document.getElementById("toWhNo");
        uiLable.style.display = "block";
    }
}


//物料库存 冻结、解冻
wmsBiz.stockInfoMaterialsStatusChange = function (tableID, oprType) {
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (wmsCommon.checkForNull(allSelectedRow) != "") {
        allSelectedRow = allSelectedRow.replace(/,/g, "|");
        var ifSucc = wmsCommon.execCommand(String.format("sys(#StockManager.stockInfoMaterialsStatusChange({0},{1}))", allSelectedRow, oprType));
        if (ifSucc == "OK") {
            wmsCommon.refThisPage();
        }
        else {
            wmsCommon.alert("执行异常，操作中止！");
        }
    }
    else {
        wmsCommon.alert("请先选择要操作的记录！");
    }
}

//库存调账 生效
wmsBiz.executeStockAjusting = function (obj) {
    var keyValue = obj.parentNode.parentNode.parentNode.keyvalue;
    if (wmsCommon.checkForNull(keyValue) != "") {
        var orderNo = keyValue.split('=')[1];
        if (confirm("确定执行" + orderNo + "？")) {
            var result = wmsCommon.execCommand(String.format("sys(#StockAjustingOrderManager.ExecuteStockAjusting({0}))", orderNo));
            if (result == "执行成功！") {
                wmsCommon.refThisPage();
            }
            wmsCommon.alert(result);
        }
    } else {
        wmsCommon.alert("主键未设置，执行中止！");
    }
}

//盘点任务 生成调账单
wmsBiz.stockAjusting = function (obj) {
    var keyValue = obj.parentNode.parentNode.parentNode.keyvalue;
    if (wmsCommon.checkForNull(keyValue) == "") {
        wmsCommon.alert("主键未设置，执行中止！");
        return;
    }
    var taskNo = keyValue.split('=')[1];
    var userNo = wmsCommon.getSessionValue("userNo");
    if (wmsCommon.checkForNull(userNo) == "") {
        alert("登录信息过期，请重新登录！");
        return;
    }
    var rootPath = wmsCommon.getRootPath();
    wmsCommon.openWin(rootPath + "/model.aspx?opt=1&model=stockAjustingOrder&temp=stockAjustingOrder_edit&takingTaskNo=" + taskNo, 900, 600);
}

//审核操作
wmsBiz.auditOrder = function (tableID, orderType, from, cnModelName) {
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (allSelectedRow != "") {
        var userName = wmsCommon.getSessionValue("userNo");
        var ifSucc = "";
        allSelectedRow = allSelectedRow.replace(/,/g, "|");
        if (wmsCommon.checkForNull(from) == "order" || wmsCommon.checkForNull(from) == "transferOrder") {
            ifSucc = wmsCommon.execCommand(String.format("sys(#OrderManager.UpdateOrderCommon({0},{1},{2},{3}))", allSelectedRow, "audit", orderType, userName));
            wmsCommon.createActionLog(cnModelName, "审核", allSelectedRow);
        }
        else if (wmsCommon.checkForNull(from) == "task") {
            ifSucc = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateTaskCommon({0},{1},{2},{3}))", allSelectedRow, "audit", orderType, userName));
            wmsCommon.createActionLog(cnModelName, "审核", allSelectedRow);
        }
        if (ifSucc == "YES") {
            wmsCommon.refThisPage();
        }
        else {
            wmsCommon.alert("审核操作失败，请与管理员联系！");
        }
    }
    else {
        wmsCommon.alert("请先选择需要审核的信息！");
    }
}

/*工作流流转
参数：oprType
submit     提交
rollback   回退
audit      审核
backout    撤销
delete     删除

exec       执行
pause      暂停
over       结束
*/
wmsBiz.workFlow = function (tableID, orderType, from, oprType) {
    var oprTypeName = wmsBiz.GetworkFlowOprType(oprType);
    var cnModelName = "";
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (allSelectedRow != "") {
        var userName = wmsCommon.getSessionValue("userNo");
        if (wmsCommon.checkForNull(userName) == "") {
            wmsCommon.popAlert("", "登录信息过期，请重新登录！", "", "");
            return;
        }
        var sMsg = "";
        allSelectedRow = allSelectedRow.replace(/,/g, "|");
        if (oprType == "delete" && !confirm("是否确定要" + oprTypeName + "选择的信息?")) {
            return false;
        }
        if (wmsCommon.checkForNull(from) == "order" || wmsCommon.checkForNull(from) == "transferOrder") {
            sMsg = wmsCommon.execCommand(String.format("sys(#OrderManager.GotoWorkFlow({0},{1},{2},{3}))", allSelectedRow, oprType, orderType, userName));
            cnModelName = wmsCommon.execCommand(String.format("sys(#SysDictManager.GetDictText(orderTypeTable_order,{0}))", orderType));
            wmsCommon.createActionLog(cnModelName, oprTypeName, allSelectedRow);
        }
        else if (wmsCommon.checkForNull(from) == "task") {
            sMsg = wmsCommon.execCommand(String.format("sys(#TaskManager.GotoWorkFlow({0},{1},{2},{3}))", allSelectedRow, oprType, orderType, userName));
            cnModelName = wmsCommon.execCommand(String.format("sys(#SysDictManager.GetDictText(orderTypeTable_task,{0}))", orderType));
            wmsCommon.createActionLog(cnModelName, oprTypeName, allSelectedRow);
        }

        var strHtml = sMsg;
        var fresh = (strHtml.indexOf("【成功】") > 0 ? '1' : '0');
        //wmsCommon.popHtml("", strHtml, fresh, 750, 300);
        var sUrl = wmsCommon.getRootPath() + "\\SysFiles\\Templates\\statusChanges.htm";
        var vReturnValue = window.showModalDialog(sUrl, strHtml, "dialogWidth=750px;dialogHeight=300px;status=no;scroll=yes");
        if (fresh == "1") {
            wmsCommon.refThisPage();
        }
    }
    else {
        wmsCommon.popAlert("", "请先选中需要操作的记录！", "", "");
    }
}

wmsBiz.GetworkFlowOprType = function (oprType) {
    if (oprType == "submit") return "提交";
    else if (oprType == "rollback") return "回退";
    else if (oprType == "audit") return "审核";
    else if (oprType == "backout") return "撤销";
    else if (oprType == "delete") return "删除";
    else if (oprType == "exec") return "执行";
    else if (oprType == "pause") return "暂停";
    else if (oprType == "over") return "结束";
}

wmsBiz.stockTaskSending = function (obj, sendingType) {
    var keyValue = obj.parentNode.parentNode.keyvalue;

    if (wmsCommon.checkForNull(keyValue) != "") {
        var rootPath = wmsCommon.getRootPath();
        var primary = keyValue;
        wmsCommon.openWin(rootPath + "/model.aspx?opt=2&model=stockTaskSending&temp=stockTask_sending&sendingType=" + sendingType + "&primary=" + primary, 600, 400);
    }
}

wmsBiz.stockSaveSending = function (obj) {
    var taskNo = document.all("taskCommon$taskNo$0").value;
    var userName = document.all("taskCommon$excuterNo$0").value;

    var result = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateExecuter({0},{1}))", taskNo, userName));
    var resultState = wmsCommon.execCommand(String.format("sys(#TaskManager.UpdateStateToSengding({0}))", taskNo));
    if (result == "True" && resultState == "True") {
        wmsCommon.refParentPage();
        wmsCommon.alert("下发成功！");
    }
}

///////edit页面公用

wmsBiz.setObjText = function (obj, i, text) {
    if (obj[i].firstChild && obj[i].firstChild.childNodes.length > 0)  //兼容嵌套的<nobr>及其他单层节点
        obj[i].firstChild.firstChild.nodeValue = text;
    else
        obj[i].innerText = wmsCommon.checkForNull(text);
}

wmsBiz.setObjValue = function (obj, i, text) {
    obj[i].childNodes[0].childNodes[0].value = wmsCommon.checkForNull(text.toString());
}


//获取根据物料码获取 物料名称 和 单位
wmsBiz.getMaterialFullName = function (obj, from) {
    var materialCode = obj.value.replace(/(\s*$)/g, "");
    var td = obj.parentNode.parentNode
    var child = td.parentNode.childNodes;
    if (wmsCommon.checkForNull(materialCode) == "") {
        wmsBiz.setObjText(child, 2, "");
        wmsBiz.GetMaterialUnits(obj, from);
    } else {
        try {
            var rtn = wmsCommon.execCommand(String.format("sys(#MaterialManager.CheckMaterialCode({0}))", escape(materialCode)));
            if (rtn != "true") {
                alert("物料码不符合规范，请重新填写！");
                obj.focus();
                obj.select();
                return false;
            }
            var materialName = wmsCommon.execCommand(String.format("sys(#MaterialManager.GetMaterialName({0}))", escape(materialCode)));
            if (materialName != undefined && wmsCommon.checkForNull(materialName) != "") {
                wmsBiz.setObjText(child, 2, wmsCommon.checkForNull(materialName));
                wmsBiz.GetMaterialUnits(obj, from);
            }
            else {
                obj.focus();
                obj.select();
                return false;
            }
        } catch (e) {
            return;
        }
    }
}

//根据物料码得到单位
wmsBiz.GetMaterialUnits = function (obj, from) {
    //移位列表赋值
    var td = obj.parentNode.parentNode;
    var child = td.parentNode.childNodes;
    var materialCode = obj.value.replace(/(\s*$)/g, "");
    if (wmsCommon.checkForNull(materialCode) == "") {
        wmsBiz.setUnitValue(child, from, "", "", "");
    }
    else {
        try {
            var rtn = wmsCommon.execCommand(String.format("sys(#MaterialManager.GetMaterialUnits({0}))", escape(materialCode)));
            if (wmsCommon.checkForNull(rtn) != "") {
                wmsBiz.setUnitValue(child, from, eval(rtn)[0]["unit"], eval(rtn)[0]["unit2"], eval(rtn)[0]["unit3"]);
            }
        } catch (e) { }
    }
}


//对单位赋值
wmsBiz.setUnitValue = function (child,from, unit, unit2, unit3) {
    if (wmsCommon.checkForNull(from) == "stockTransferOrder_materials") {
        wmsBiz.setObjText(child, 7, wmsCommon.checkForNull(unit));
        wmsBiz.setObjText(child, 9, wmsCommon.checkForNull(unit2));
        wmsBiz.setObjText(child, 11, wmsCommon.checkForNull(unit3));
    }
    else if (wmsCommon.checkForNull(from) == "unpackOrder_materials" || wmsCommon.checkForNull(from) == "packingTask_materials" || wmsCommon.checkForNull(from) == "unpackTask_materials") {
        wmsBiz.setObjText(child, 3, wmsCommon.checkForNull(unit));
        wmsBiz.setObjText(child, 5, wmsCommon.checkForNull(unit2));
        wmsBiz.setObjText(child, 7, wmsCommon.checkForNull(unit3));
    }
    else if (wmsCommon.checkForNull(from) == "stockTakingTask_materials") {
        wmsBiz.setObjText(child, 6, wmsCommon.checkForNull(unit));
    }
    else if (wmsCommon.checkForNull(from) == "stockAjusting_materials") {
        wmsBiz.setObjText(child, 7, wmsCommon.checkForNull(unit));
    }
    else if (wmsCommon.checkForNull(from) == "task") {
        wmsBiz.setObjText(child, 6, wmsCommon.checkForNull(unit));
        wmsBiz.setObjText(child, 8, wmsCommon.checkForNull(unit2));
        wmsBiz.setObjText(child, 10, wmsCommon.checkForNull(unit3));
    }
    else {
        wmsBiz.setObjText(child, 5, wmsCommon.checkForNull(unit));
        wmsBiz.setObjText(child, 7, wmsCommon.checkForNull(unit2));
        wmsBiz.setObjText(child, 9, wmsCommon.checkForNull(unit3));
    }
}



//数量换算
wmsBiz.countNum = function (obj, from) {
    if (wmsCommon.checkForNull(obj) == "") return;
    var numValue = obj.value;
    var td = obj.parentNode.parentNode;
    var unit = td.nextSibling.childNodes[0];
    if (wmsCommon.checkForNull(unit) == "") return;
    var unit = unit.nodeValue.replace(/(\s*$)/g, " ");
    var materialCode = td.parentNode.childNodes[1].childNodes[0].childNodes[0].value.replace(/(\s*$)/g, "");
    if (materialCode.length == 0)
        return;
    if (wmsCommon.checkForNull(materialCode) == "") return;
    var rtn = eval(wmsCommon.execCommand(String.format("sys(#MaterialManager.UnitTransfer({0},{1},{2}))", materialCode, unit, Number(numValue))));
    if (wmsCommon.checkForNull(rtn) != "") {
        var num1 = rtn[0]["num1"];
        var num2 = rtn[0]["num2"];
        var num3 = rtn[0]["num3"];
        var child = td.parentNode.childNodes;
        if (wmsCommon.checkForNull(from) == "stockTransferOrder_materials") {
            wmsBiz.setObjValue(child, 6, num1);
            wmsBiz.setObjValue(child, 8, num2);
            wmsBiz.setObjValue(child, 10, num3);
        }
        else if (wmsCommon.checkForNull(from) == "stockAjusting_materials") {
            wmsBiz.setObjValue(child, 6, num1);
            wmsBiz.setObjValue(child, 11, num1);
            wmsBiz.setObjValue(child, 13, num1);
        } else {
            wmsBiz.setObjValue(child, 4, num1);
            wmsBiz.setObjValue(child, 6, num2);
            wmsBiz.setObjValue(child, 8, num3);
        }
    }
}

//数量换算 物料明细有货位的情况
wmsBiz.countNumTask = function (obj, from) {

    if (wmsCommon.checkForNull(obj) == "") return;
    var numValue = obj.value;
    var td = obj.parentNode.parentNode;
    var unit = td.nextSibling.childNodes[0].nodeValue.replace(/(\s*$)/g, " ");
    var materialCode = td.parentNode.childNodes[1].childNodes[0].childNodes[0].value.replace(/(\s*$)/g, "");
    if (materialCode.length == 0)
        return;
    if (wmsCommon.checkForNull(materialCode) == "") return;
    var rtn = eval(wmsCommon.execCommand(String.format("sys(#MaterialManager.UnitTransfer({0},{1},{2}))", materialCode, unit, Number(numValue))));
    if (wmsCommon.checkForNull(rtn) != "") {
        var num1 = rtn[0]["num1"];
        var num2 = rtn[0]["num2"];
        var num3 = rtn[0]["num3"];
        var child = td.parentNode.childNodes;
        if (wmsCommon.checkForNull(from) == "stockTransferOrder_materials") {
            wmsBiz.setObjValue(child, 6, num1);
            wmsBiz.setObjValue(child, 8, num2);
            wmsBiz.setObjValue(child, 10, num3);
        }
        else {
            wmsBiz.setObjValue(child, 5, num1);
            wmsBiz.setObjValue(child, 7, num2);
            wmsBiz.setObjValue(child, 9, num3);
        }
    }
}

wmsBiz.getMaterialInfo = function (obj) {
    if (wmsCommon.checkForNull(obj) == "") return;
    var serialNo = obj.value.replace(/(\s*$)/g, "");
    var materialCode = wmsCommon.execCommand(String.format("sys(#SerialManager.GetMaterialCode({0}))", serialNo));
    if (wmsCommon.checkForNull(materialCode) == "") return;
    var child = obj.parentNode.parentNode.childNodes;
    wmsBiz.setObjValue(child, 2, materialCode);
}


//打开对应的单据
wmsBiz.openOrderDetails = function (keyValue, orderType, orderTable) {
    if (wmsCommon.checkForNull(keyValue) != "" && wmsCommon.checkForNull(orderType) != "" && wmsCommon.checkForNull(orderTable) != "") {
        var checkRtn = wmsCommon.execCommand(String.format("sys(#AlarmManager.CheckOrder('{0}','{1}'))", escape(orderTable), escape(keyValue)));
        if (checkRtn != "True") {
            alert("未找到对应的单据！");
            return;
        }
        switch (orderTable.toUpperCase()) {
            case "STOCKINORDER":
                {
                    return wmsCommon.openLookWin(keyValue, "stockInOrder", "stockInOrder_view", 900, 600);
                }
            case "STOCKOUTORDER":
                {
                    return wmsCommon.openLookWin(keyValue, "stockOutOrder", "stockOutOrder_view", 900, 600);
                }
            case "STOCKINTASK":
                {
                    return wmsCommon.openLookWin(keyValue, "stockInTask", "stockInTask_view", 900, 600);
                }
            case "STOCKOUTTASK":
                {
                    return wmsCommon.openLookWin(keyValue, "stockOutTask", "stockOutTask_view", 900, 600);
                }
        }
    }
    else {
        alert("未找到对应的单据！");
    }
}

//根据仓库wbs打开打开货位图
wmsBiz.wareHouseClick = function (wareHouseWBS) {
    if (wmsCommon.checkForNull(wareHouseWBS) == "") return;
    var root = wmsCommon.getRootPath();
    var url = root + "/DepotImg.aspx?model=depot&wareHouseWBS=" + wareHouseWBS;
    window.location.href = encodeURI(url);
}



var lastObj = null;
//点击货位事件
/*
wmsBiz.depotClick = function (obj) {
var td = obj.parentNode;
if (lastObj != null) {
lastObj.style.backgroundColor = "";
lastObj.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.backgroundColor = "";
lastObj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].style.backgroundColor = "";
lastObj.childNodes[0].childNodes[0].childNodes[1].childNodes[0].style.backgroundColor = "";
if (lastObj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes.length > 0) {
lastObj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.backgroundColor = "#FFFFFF";
lastObj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[0].style.backgroundColor = "#FFFFFF";
}
}
lastObj = obj;
obj.style.backgroundColor = "rgb(255,204,102)";
obj.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.backgroundColor = "rgb(255,204,102)";
obj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].style.backgroundColor = "rgb(255,204,102)";
obj.childNodes[0].childNodes[0].childNodes[1].childNodes[0].style.backgroundColor = "rgb(255,204,102)";
if (obj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes.length > 0) {
obj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.backgroundColor = "rgb(255,204,102)";
obj.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[1].childNodes[0].style.backgroundColor = "rgb(255,204,102)";
}

wbsCode = obj.wbsCode;

//填充右边列表信息
wmsBiz.fillDepotInfo(wbsCode);
wmsBiz.fillStockInfo(wbsCode);
}


//填充货位存放信息数据
wmsBiz.fillStockInfo = function (depotWBSCode) {
if (wmsCommon.checkForNull(wbsCode) == "") return;
var rtn = eval(wmsCommon.execCommand("sys(#DepotInfoManager.GetDepotStockInfo(" + depotWBSCode + "))"));
var depotStockInfoTableHTML = "";
if (wmsCommon.checkForNull(rtn) == "") {
depotStockInfoTableHTML = wmsBiz.createTableHTML("", "", "", "", "", 0)
}
else {
for (var i = 0; i < rtn.length; i++) {
depotStockInfoTableHTML += wmsBiz.createTableHTML(rtn[i]["materialName"], rtn[i]["materialCode"], rtn[i]["batchNo"], rtn[i]["num"], rtn[i]["unit"], i)
}
}
if (depotStockInfoTableHTML != "") {
var div = document.getElementById("depotStockInfoDiv");
div.innerHTML = depotStockInfoTableHTML;
}
}

//生成货位存储信息列表
wmsBiz.createTableHTML = function (materialName, materialCode, batchNo, num, unit, intNum) {
if (wmsCommon.checkForNull(intNum) == "") intNum = 0;
var tableHTML = "<table  class='depotStockInfo'  cellspacing='0'; cellpadding='0' >"
+ " <tr><td width='50px'>物料名称</td><td colspan='3'><input type='text' name='materialName" + intNum + "'   value='" + materialName + "'   class='inputText' readOnly /></td>"
+ "<tr><td width='40px'>物料码</td><td width='90px'><input type='text' class='inputText' readOnly  name='materialCode" + intNum + "'  value='" + materialCode + "' /></td>"
+ "<td width='40px'>&nbsp;批号</td><td width='90px'><input type='text' name='batchNo" + intNum + "' class='inputText'  value='" + batchNo + "' readOnly /></td></tr>"
+ "<tr><td width='40px'>数量</td><td width='90px'><input type='text' name='num" + intNum + "' class='inputText' readOnly   value='" + num + "' /></td>"
+ "<td width='40px'>&nbsp;单位</td><td width='90px'><input type='text'  name='unit" + intNum + "' class='inputText' readOnly   value='" + unit + "' /></td></tr>"
+ "</table><hr>";
return tableHTML;
}
wmsBiz.openDetailWin = function () {
var depotWMSCode = document.getElementById("depotWBS").value;
if (wmsCommon.checkForNull(depotWMSCode) != "") {
wmsCommon.openLookWin("wbsCode=" + depotWMSCode, "warehouse_depots", "depotStockInfo_list", 1000, 600)
}
else {
wmsCommon.alert("请先选择货位！");
}
}

*/
//填充货位信息数据
wmsBiz.fillDepotInfo = function (depotWBSCode) {
    if (wmsCommon.checkForNull(depotWBSCode) == "") return;
    var rtn = eval(wmsCommon.execCommand("sys(#DepotInfoManager.GetDepotInfo(" + depotWBSCode + "))"));
    if (wmsCommon.checkForNull(rtn) == "") return;
    wmsBiz.setInputValue("depotWBS", wmsCommon.checkForNull(depotWBSCode));
    wmsBiz.setInputValue("depotName", wmsCommon.checkForNull(rtn[0].depotName));
    wmsBiz.setInputValue("depotType", wmsCommon.checkForNull(rtn[0].depotType));
    wmsBiz.setInputValue("depotStatus", wmsCommon.checkForNull(rtn[0].status));
    wmsBiz.setInputValue("depotPicNo", wmsCommon.checkForNull(rtn[0].picNo));
    wmsBiz.setInputValue("depotPicPhone", wmsCommon.checkForNull(rtn[0].picPhone));
    wmsBiz.setInputValue("depotAddress", wmsCommon.checkForNull(rtn[0].address));
    wmsBiz.setInputValue("depotNotes", wmsCommon.checkForNull(rtn[0].notes));
}
wmsBiz.setInputValue = function (objId, value) {
    var obj = document.getElementById(objId);
    if (wmsCommon.checkForNull(obj) == "") return;
    try {
        obj.value = value;
    } catch (e) { }
}



//根据仓库wbs打开打开货位图2
wmsBiz.wareHouseClick2 = function (wareHouseWBS, warehouseName) {
    if (wmsCommon.checkForNull(wareHouseWBS) == "") return;
    var root = wmsCommon.getRootPath();
    var url = root + "/Model.aspx?opt=3&model=wh_area_depots&temp=depotsInfo&warehouseName=" + encodeURI(warehouseName) + encodeURI("&con=wbsCode like '" + wareHouseWBS + "%'");
    window.location.href = url;
}

//点击货位事件
var lastDiv = null;
wmsBiz.depotClick2 = function (obj) {
    var wbsCode = obj.wbsCode;
    if (lastDiv != null) {
        lastDiv.style.backgroundColor = "";
    }
    obj.style.backgroundColor = "rgb(255,204,102)";
    lastDiv = obj;
    wmsBiz.fillDepotInfo(wbsCode);
    wmsBiz.fillStockInfo2(wbsCode);
}

//填充货位存放信息数据
wmsBiz.fillStockInfo2 = function (depotWBSCode) {

    if (wmsCommon.checkForNull(depotWBSCode) == "") return;
    var rtn = eval(wmsCommon.execCommand("sys(#DepotInfoManager.GetDepotStockInfo(" + depotWBSCode + "))"));

    if (wmsCommon.checkForNull(rtn) == "") {
        wmsBiz.setInputValue("materialName", "");
        wmsBiz.setInputValue("materialCode", "");
        wmsBiz.setInputValue("batchNo", "");
        wmsBiz.setInputValue("num", "");
        wmsBiz.setInputValue("unit", "");
        wmsBiz.setInputValue("lastInTime", "");
        wmsBiz.setInputValue("lastOutTime", "");
    }
    else {
        var materialName = "", materialCode = "", batchNo = "", num = "", unit = "", lastInTime = "", lastOutTime = "";
        for (var i = 0; i < rtn.length; i++) {
            materialName += wmsCommon.checkForNull(rtn[i].materialName) + "、";
            materialCode += wmsCommon.checkForNull(rtn[i].materialCode) + "、";
            batchNo += wmsCommon.checkForNull(rtn[i].batchNo) + "、";
            num += wmsCommon.checkForNull(rtn[i].num) + "、";
            unit += wmsCommon.checkForNull(rtn[i].unit) + "、";
            lastInTime += wmsCommon.checkForNull(rtn[i].lastInTime) + "、";
            lastOutTime += wmsCommon.checkForNull(rtn[i].lastOutTime) + "、";
        }
        wmsBiz.setInputValue("materialName", wmsBiz.DropLastSymbol(materialName));
        wmsBiz.setInputValue("materialCode", wmsBiz.DropLastSymbol(materialCode));
        wmsBiz.setInputValue("batchNo", wmsBiz.DropLastSymbol(batchNo));
        wmsBiz.setInputValue("num", wmsBiz.DropLastSymbol(num));
        wmsBiz.setInputValue("unit", wmsBiz.DropLastSymbol(unit));
        wmsBiz.setInputValue("lastInTime", wmsBiz.DropLastSymbol(lastInTime));
        wmsBiz.setInputValue("lastOutTime", wmsBiz.DropLastSymbol(lastOutTime));
    }
}

wmsBiz.DropLastSymbol = function (express) {
    if (wmsCommon.checkForNull(express) == "") return "";
    if (express.length > 0)
        return express.substring(0, express.length - 1);
}

//生成移位任务 ，修改单据状态  并 打开生成的移位任务单 修改页面
wmsBiz.generateTransferTask = function (qualityNo) {
    qualityNo = qualityNo.split('=')[1];
    var keyValue = wmsCommon.execCommand(String.format("sys(#QualityCheckManager.GenerateStockTransferTask({0}))", qualityNo));
    if (keyValue != "") {
        //stockTakingTask','stockTakingTask_edit'
        var model = "stockTransferTask", temp = "stockTransferTask_edit", width = "600", hight = "400";
        var rootPath = wmsCommon.getRootPath();
        wmsCommon.openWin(rootPath + "/model.aspx?opt=2&model=" + model + "&temp=" + temp + "&primary=" + encodeURI(keyValue), width, hight);
    }
}


//}
//任务添加质检，现生成质检，然后展示修改页面
wmsBiz.openQualitied = function (model, temp, width, hight, qualityParam) {
    var generateResult = wmsCommon.execCommand(String.format("sys(#QualityCheckManager.GenerateQualityByTask({0}))", qualityParam));
    if (wmsCommon.checkForNull(generateResult) == "") return;
    var keyValue = generateResult;
    if (wmsCommon.checkForNull(keyValue) == "") return;
    if (wmsCommon.checkForNull(width) == "") width = 900;
    if (wmsCommon.checkForNull(hight) == "") hight = 600;
    var rootPath = wmsCommon.getRootPath();
    wmsCommon.openWin(rootPath + "/model.aspx?opt=2&model=" + model + "&temp=" + temp + "&primary=" + encodeURI(keyValue), width, hight);
}

//审核后修改物料,任务单,质检单,状态
wmsBiz.auditQualityMaterials = function (keyparams) {
 
    var keyArr = "";
    //    var keyparams = wmsCommon.getSelectedKeyValues(tblId);
    var reg = /([^=]*)=([^,]*)/g;
    var m;
    while ((m = reg.exec(keyparams)) != null) {
        keyArr += m[2] + ",";
    }
    if (keyArr.length > 0) {
        keyArr = keyArr.slice(0, keyArr.length - 1);
        var result = wmsCommon.execCommand(String.format("sys(#QualityCheckManager.AuditQualityModifyState('{0}'))", keyArr)); //执行修改
        alert(result);
    }
    window.location.href = window.location.href;

}
//open user role's authorization page
wmsBiz.openUsRoleAutorization = function (obj) {
    var userNo = obj.parentNode.id;
    var userName = obj.parentNode.name;
    var href = "Pages/userDeptRoleAtuthorizationMain.htm?" + "userNo=" + encodeURIComponent(userNo) + "&userName=" + encodeURIComponent(userName);
    wmsCommon.openWin(href, '800', "600");
}


//}

//跳转到我的周面
wmsBiz.myDeskTop = function () {
    var rootPath = wmsCommon.getRootPath();
    window.parent.parent.frames["main"].location.href = rootPath + "/fDefault.htm";
    window.parent.parent.frames["mapBar"].location.href = rootPath + "/SiteMapBar.htm?barMsg=我的桌面";
}

wmsBiz.openListWin = function (from, type) {
    if (wmsCommon.checkForNull(from) == "") return;
    var rootPath = wmsCommon.getRootPath();
    type = type.replace(/(^\s*)|(\s*$)/g, "");
    var filePath = "";
    var barName = "";
    if (from == "alarm") {
        filePath = "/model.aspx?model=alarms_list&temp=alarms_list&con=alarmtype='" + type + "' and  CONVERT(INT,ISNULL(status,0))<=1";
        barName = "报警管理>报警处理";
    }
    else if (from == "whstockView") {
        filePath = "/model.aspx?model=stockInfo_materials&temp=stockInfo_materials_list";
        barName = "库存管理>库存物料";
    }
    else if (from == "order") {
        if (wmsCommon.checkForNull(type) == "") return;
        switch (type) {
            case "01":  //收料单
                {
                    filePath = "/model.aspx?model=my_stockInOrderWithCommon&temp=stockInOrder_list";
                    barName = "收发料管理>收料通知";
                    break;
                }
            case "02":  //发料单
                {
                    filePath = "/model.aspx?model=my_stockOutOrderWithCommon&temp=stockOutOrder_list";
                    barName = "收发料管理>发料通知";
                    break;
                }

            case "04": //质检单
                {
                    filePath = "/model.aspx?model=my_qualityCheckOrderWithCommon&temp=qualityCheckOrder_list";
                    barName = "库内管理>质检单";
                    break;
                }

            case "03":  //库存调账单
                {
                    filePath += "/model.aspx?model=my_stockAjustingOrderWithCommon&temp=stockAjustingOrder";
                    barName = "库内管理>库存调账";
                    break;
                }
        }
    }
    else if (from == "task") {
        if (wmsCommon.checkForNull(type) == "") return;
        switch (type) {
            case "01":  //收料任务
                {
                    filePath = "/model.aspx?model=my_stockInTaskWithCommon&temp=stockInTask_list";
                    barName = "收发料管理>收料任务";
                    break;
                }
            case "02":  //发料任务
                {
                    filePath = "/model.aspx?model=my_stockOutTaskWithCommon&temp=stockOutTask_list";
                    barName = "收发料管理>发料任务";
                    break;
                }
            case "03":  //盘点任务
                {
                    filePath = "/model.aspx?model=my_stockTakingTaskWithCommon&temp=stockTakingTask_list";
                    barName = "库内管理>盘点任务";
                    break;
                }
            case "04": //移位任务
                {
                    filePath = "/model.aspx?model=my_stockTransferTaskWithCommon&temp=stockTransferTask_list";
                    barName = "库内管理>移库任务";
                    break;
                }
        }
    }
    if (filePath != "") {
        window.parent.parent.frames["mapBar"].location.href = rootPath + "/SiteMapBar.htm?barMsg=" + barName;
        window.parent.location.href = rootPath + filePath;
    }
}

//回收站撤消
wmsBiz.revocation = function (tableid) {
    if (confirm("您确定还原这些数据?")) {
        var idStr1 = ""; //task
        var idStr2 = ""; //
        if (tableid.length == 0) tableid = "contenttb";
        $('#' + tableid + ' tr:gt(0)').each(function () {//除表头的行
            var element = $(this).find("td:first>input"); //
            if (element.attr("type") == "checkbox" && element.attr("checked")) {
                if (element.attr("name") == "taskcommon") {
                    idStr1 += "'" + element.attr("id") + "',";
                }
                else if (element.attr("name") == "ordercommon") {
                    idStr2 += "'" + element.attr("id") + "',";
                }
            }
        });
        if (idStr1.length > 0) {
            idStr1 = idStr1.slice(0, idStr1.length - 1);
            var Expr = "sys(#RecyleBinManager.RevocationTask(quote{" + idStr1 + "}))";
            wmsCommon.execCommand(Expr);
        }
        if (idStr2.length > 0) {
            idStr2 = idStr2.slice(0, idStr2.length - 1);
            var Expr = "sys(#RecyleBinManager.RevocationCommon(quote{" + idStr2 + "}))";
            wmsCommon.execCommand(Expr);
        }
        window.location = window.location;
    }
}


//删除部门
wmsBiz.deleteDepartment = function (tableID, modelName) {
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (wmsCommon.checkForNull(allSelectedRow) != "") {
        if (confirm("是否确定要删除选择的信息？")) {
            var result = wmsCommon.execCommand(String.format("sys(#DepartmentManager.DeleteDeparment({0}))", escape(allSelectedRow)));
            if (result.length > 0) {
                var reArr = result.substring(0, result.length - 1).split(',');
                var message = "";
                for (var i = 0; i < reArr.length; i++) {
                    if (reArr[i].split('=')[1].split('&')[1] == 'true') {
                        message += reArr[i].split('=')[1].split('&')[0] + "删除成功!\n";
                    }
                    else {
                        message += reArr[i].split('=')[1].split('&')[0] + " 有子部门不能被删除!\n";
                    }
                }
                alert(message);
            }
            wmsCommon.refThisPage();
        }
    }
    else {
        wmsCommon.alert("请先选择需要删除的信息！");
    }
}

//删除角色
wmsBiz.deleteRoles = function (tblID) {
    var prometText = "删除该角色,将会删除所有用户的该角色权限,确定要删除?";
    wmsCommon.relatedDelete(tblID, "roleinfo,roleModules", prometText);
}
